package com.example.sys.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sys.entity.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author 罗文斌
 * @Date 2023/7/24
 * @Version 1.0.0
 */
@Mapper
public interface PermissionMapper {

    Page<Permission> getPermission(Page<Permission> page, String siftName);

    @Select("select id, name, label from sys_role where name = #{role}")
    Permission getRole(String role);

    @Insert("insert into sys_role(id, name, label) values (#{id}, #{role}, #{roleName})")
    int addRole(long id, String role, String roleName);

    @Insert("insert into sys_role_menu(role, menu_id) values (#{id}, #{menu})")
    int addRoleRelation(long id, String menu);

    @Update("update sys_role set name = #{name}, label = #{label} where id = #{id}")
    int updateRole(Integer id, String name, String label);

    @Delete("delete from sys_role_menu where role = #{id}")
    int removeAllByRole(Integer id);

    @Delete("delete from sys_role where id = #{id}")
    int removeRole(Integer id);
}
